﻿//**************************************************
//CLASS : tcdc_mst_member_type
//AUTHOR : PATTARAWUT CHANNGAM & SUCHIN INPIRUT
//LAST MODIFIED : Monday, February 25, 2013
//**************************************************

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.SqlClient;

namespace Model
{

public class tcdc_mst_member_type
{

     private DBUtil DB;
     public string strConn { get; set; }
     public int member_type_id {get;set;}
     public string member_type_name_th {get;set;}
     public string member_type_name_en {get;set;}

     public tcdc_mst_member_type() {
          this.DB = new DBUtil();
          DB.strConn = strConn;
     }

     public DataTable getById(string id) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_member_type" + 
                       " WHERE member_type_id = '" + id + "'";

          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public DataTable getByObject(tcdc_mst_member_type obj) {

          DataTable dt = new DataTable();
          this.DB = new DBUtil();
          DB.strConn = strConn;

          string sql = "SELECT * FROM tcdc_mst_member_type " + 
                       "WHERE 1 = 1 ";

          if(obj.member_type_id != null && 
             obj.member_type_id.ToString() != null && 
             obj.member_type_id.ToString() != "0")
          {
               sql += "AND member_type_id LIKE '%" + obj.member_type_id + "%' ";
          }
          if(obj.member_type_name_th != null && 
             obj.member_type_name_th.ToString() != null && 
             obj.member_type_name_th.ToString() != "0")
          {
               sql += "AND member_type_name_th LIKE '%" + obj.member_type_name_th + "%' ";
          }
          if(obj.member_type_name_en != null && 
             obj.member_type_name_en.ToString() != null && 
             obj.member_type_name_en.ToString() != "0")
          {
               sql += "AND member_type_name_en LIKE '%" + obj.member_type_name_en + "%' ";
          }
          dt = DB.ExecuteReader(sql);

          return dt;

     }

     public int insertData(tcdc_mst_member_type obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[3];

          prm[0] = new SqlParameter("@member_type_name_th", SqlDbType.NVarChar,250);
          if(obj.member_type_name_th != null && 
             obj.member_type_name_th.ToString() != null && 
             obj.member_type_name_th.ToString() != "0")
          {
               prm[0].Value = obj.member_type_name_th;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }

          prm[1] = new SqlParameter("@member_type_name_en", SqlDbType.NVarChar,250);
          if(obj.member_type_name_en != null && 
             obj.member_type_name_en.ToString() != null && 
             obj.member_type_name_en.ToString() != "0")
          {
               prm[1].Value = obj.member_type_name_en;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }

          prm[2] = new SqlParameter("@ReturnValue", SqlDbType.Int);
          prm[2].Direction = ParameterDirection.Output;

          DB.ExecuteNonQueryProc("sp_tcdc_mst_member_type_insert", prm, false);
          return (Int32)prm[2].Value;
     }

     public int updateData(tcdc_mst_member_type obj) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[3];

          prm[0] = new SqlParameter("@member_type_id", SqlDbType.Int);
          if(obj.member_type_id != null && 
             obj.member_type_id.ToString() != null && 
             obj.member_type_id.ToString() != "0")
          {
               prm[0].Value = obj.member_type_id;
          }
          else
          {
               prm[0].Value = DBNull.Value;
          }
          prm[1] = new SqlParameter("@member_type_name_th", SqlDbType.NVarChar,250);
          if(obj.member_type_name_th != null && 
             obj.member_type_name_th.ToString() != null && 
             obj.member_type_name_th.ToString() != "0")
          {
               prm[1].Value = obj.member_type_name_th;
          }
          else
          {
               prm[1].Value = DBNull.Value;
          }
          prm[2] = new SqlParameter("@member_type_name_en", SqlDbType.NVarChar,250);
          if(obj.member_type_name_en != null && 
             obj.member_type_name_en.ToString() != null && 
             obj.member_type_name_en.ToString() != "0")
          {
               prm[2].Value = obj.member_type_name_en;
          }
          else
          {
               prm[2].Value = DBNull.Value;
          }

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_member_type_update", prm, false);
     }

     public int deleteData(string id) {

          this.DB = new DBUtil();
          DB.strConn = strConn;

          SqlParameter[] prm;
          prm = new SqlParameter[1];

          prm[0] = new SqlParameter("@member_type_id", id);

          return DB.ExecuteNonQueryProc("sp_tcdc_mst_member_type_delete", prm, false);
     }
}

}

